package com.example.testmvp;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/23.
 */

public class FlexBoxAdapter extends RecyclerView.Adapter<FlexBoxViewHolder> {

    private LayoutInflater inflater;
    private Context context;
    private String[] strs;

    public FlexBoxAdapter(Context context, String[] strs) {
        this.context = context;
        this.strs = strs;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public FlexBoxViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.recycle_item, parent, false);
        FlexBoxViewHolder holder = new FlexBoxViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(FlexBoxViewHolder holder, int position) {

        Glide.with(context).load(strs[position]).centerCrop().into(holder.itemImg);
    }

    @Override
    public int getItemCount() {
        return strs.length;
    }
}

class FlexBoxViewHolder extends RecyclerView.ViewHolder {
    @Bind(R.id.item_img)
    ImageView itemImg;

    public FlexBoxViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this,itemView);
    }
}